package a02_Thread;

/**
 * @Author quan
 * @Description 判断线程结束前后的状态和是否存活
 * @Date 2023/4/28 13:58
 */
public class Demo7_Join {
    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("hello thread" + i);
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();
        System.out.println("join之前，线程状态："+ thread.getState());
        System.out.println("join之前，是否存活："+ thread.isAlive());
        //使用join等待thread线程结束
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("join之后，线程状态："+ thread.getState());
        System.out.println("join之后，是否存活：" + thread.isAlive());

    }
}
